//
//  TJNavigationViewController.swift
//  WeiBo
//
//  Created by TanJian on 15/12/5.
//  Copyright © 2015年 Joshpell. All rights reserved.
//

import UIKit

class TJNavigationViewController: UINavigationController , UIGestureRecognizerDelegate{

    override func viewDidLoad() {
        super.viewDidLoad()

        view.backgroundColor = UIColor.whiteColor()
        
        self.interactivePopGestureRecognizer?.delegate = self
    }

    override func pushViewController(viewController: UIViewController, animated: Bool) {
        
        if childViewControllers.count != 0{
            
            var title : String = "返回"
            
            viewController.hidesBottomBarWhenPushed = true
            
            //如果是子控制器，改变title
            if childViewControllers.count == 1{
                
                title = childViewControllers.first!.title ?? title
                
            }
            
            //给navbar的左按钮赋值
            viewController.navigationItem.leftBarButtonItem = UIBarButtonItem(title: title, imgName: "navigationbar_back_withtext", target: self , action: "back")
            
        }
        
        super.pushViewController(viewController, animated: true)
        
    }
    
    func back() {
        
        popViewControllerAnimated(true)
        
    }
    
    //实现手势滑动的代理方法，首页控制器则不滑动
    func gestureRecognizerShouldBegin(gestureRecognizer: UIGestureRecognizer) -> Bool {
        
        print("手势滑动")

        return childViewControllers.count != 1
        
    }

}
